#ifndef XGTHREAD_H
#define XGTHREAD_H

#include <windows.h>

class XgThread;

#include "XgMessagesProcessor.h"
#include "Templates/XgSignal.h"
#include "Templates/XgInvokable.h"
#include "XgMessagesQueue.h"

DWORD WINAPI xg_thread_proc( LPVOID );

/************************************************************************/
/* XgThread                                                             */
/************************************************************************/
class XgThread : public XgMessagesProcessor
{

friend DWORD WINAPI xg_thread_proc( LPVOID );

public:
	XgThread();
	~XgThread();

public: //signals
	signal() onCreate;
	signal() onMessagesQueueCreate;

public:
	void create();
	void postMessage(XgMessage* xgmsg);

protected:
	virtual void run() = 0;
	void exec();
	void exit( DWORD ret );

private:
	void xg_run( LPDWORD ret );
	
private:
	HANDLE m_hThread;
	DWORD m_idThread;
	LPDWORD m_retThread;
	XgMessagesQueue* m_queueThread;
};

#endif //XGTHREAD_H
